package com.zhao.savepassword;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.util.ArrayList;

/**
 * Created by zhao on 16-2-4.
 */
public class AccountListFragment extends ListFragment{
    private ArrayList<Account> list;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        list = AccountActivity.getList();
        ArrayAdapter<Account> adapter = new AccountAdapter(list);
        setListAdapter(adapter);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    /**
     * 建立内部类 adapter
     */
    public class AccountAdapter extends ArrayAdapter<Account>{
        public AccountAdapter(ArrayList<Account> list) {
            super(getActivity(),0,list);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = View.inflate(getActivity(),R.layout.crime_account,null);
            TextView tv_userName = (TextView)v.findViewById(R.id.tv_user_name);
            TextView tv_userRemarks = (TextView)v.findViewById(R.id.tv_user_remarks);

            Account account = getItem(position);
            tv_userName.setText(account.getUser());
            tv_userRemarks.setText(account.getRemarks());
            return v;

        }
    }
}
